﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AP.Framework.Infrastructure.Repositories.IRepositories;
using AP.Framework.Infrastructure.Entities;

namespace AP.Web.Areas.Admin.Controllers
{
    public class ArticleCategoryController : Controller
    {

        IArticleCategory _articleCategory;
        public ArticleCategoryController(IArticleCategory articleCategory)
        {
            _articleCategory = articleCategory;
        }
        public ActionResult Index()
        {
            var articleCategoryList = _articleCategory.GetAll().OrderBy(p => p.Sequence).ToList();
            return View(articleCategoryList);
        }
        public ActionResult Add()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Add(cms_ArticleCategory model)
        {
            if (ModelState.IsValid)
            {
                model.ModifyBy = "Admin";
                model.ModifyTime = DateTime.Now.Date;
                _articleCategory.Add(model);
            }
            return RedirectToAction("Index");
        }
        public ActionResult Edit(int ArticleCategoryId)
        {
            cms_ArticleCategory model = _articleCategory.FindById(ArticleCategoryId);
            return View(model);
        }
        [HttpPost]
        public ActionResult Edit(cms_ArticleCategory model)
        {
            if (ModelState.IsValid)
            {
                model.ModifyBy = "Admin";
                model.ModifyTime = DateTime.Now.Date;
                _articleCategory.Modify(model);
            }
            return RedirectToAction("Index");
        }

        public ActionResult Delete(int ArticleCategoryId)
        {
            cms_ArticleCategory model = _articleCategory.FindById(ArticleCategoryId);
            _articleCategory.Remove(model);
            return RedirectToAction("Index");
        }
    }
}
